//引入封装的axios实例
import axios from '@/utils/request'


//登录请求
async function getGo(params) {
  let { data } = await axios.post('login', params)
  return data
}

//用户数据列表请求
async function getList(params) {
  let { data } = await axios.get(`users?query=${params.query}&pagenum=${params.pagenum}&pagesize=${params.pagesize}`, params)
  return data
}

//添加用户请求
async function getadd(params) {
  let { data } = await axios.post('users', params)
  return data
}

//修改用户状态
async function getstatus(params) {
  // console.log(params);
  let { data } = await axios.put(`users/${params.uId}/state/${params.type}`, params)
  return data
}

//搜索
// async function getSeek(params) {
//   // console.log(params);
//   let { data } = await axios.get(`users/${params.id}`, params)
//   return data
// }

//编辑
async function getcom(params) {
  let { data } = await axios.put(`users/${params.id}`, params)
  return data
}

//删除
async function Delete(params) {
  let { data } = await axios.delete(`users/${params.id}`, params)
  return data
}

//分配角色
async function getAll(params) {
  let { data } = await axios.put(`users/${params.id}/role?body=${params.rid}`, params)
  return data
}

//请求角色列表
async function roleList(params) {
  let { data } = await axios.get('roles', params)
  return data
}
// ---------权限管理板块---------
//请求权限列表1
async function getjur(params) {
  // console.log(params);
  let { data } = await axios.get(`rights/${params}`, params)
  return data
}

//请求权限列表2
async function getjur2(params) {
  let { data } = await axios.get(`rights/${params.type}`, params)
  return data
}

//添加角色请求
async function getAddrole(params) {
  let { data } = await axios.post('roles', params)
  return data
}

//编辑角色请求
async function getEdit(params) {
  let { data } = await axios.put(`roles/${params.id}`, params)
  return data
}

//删除角色请求
async function getDel(params) {
  let { data } = await axios.delete(`roles/${params.id}`, params)
  return data
}

//角色授权请求
async function getAut(params) {
  let { data } = await axios.post(`roles/${params.roleId}/rights`, params)
  return data
}

//删除角色指定权限
async function wipeJur(params) {
  let { data } = await axios.delete(`roles/${params.roleId}/rights/${params.rightId}`, params)
  return data
}

//商品列表请求
async function getGoods(params) {
  let { data } = await axios.get(`goods?query=${params.query}&pagenum=${params.pagenum}&pagesize=${params.pagesize}`, params)
  return data
}

//商品分类请求
async function getCat(params) {
  let { data } = await axios.get('categories', params)
  return data
}

//添加商品请求
async function add(params) {
  let { data } = await axios.post('goods', params)
  return data
}

// //查询商品请求
// async function seek(params){
//   let { data } = await axios.get(`goods/${params}`,params)
//   return data
// }

//编辑商品请求
async function edit(params) {
  // console.log(params);
  let { data } = await axios.put(`goods/${params.id}`, params)
  return data
}

//删除商品请求
async function dels(params) {
  let { data } = await axios.delete(`goods/${params}`, params)
  return data
}

//订单数据列表
async function orderList(params) {
  let { data } = await axios.get(`orders?pagenum=${params.pagenum}&pagesize=${params.pagesize}`, params)
  return data
}

//物流信息数据
async function logistics(params) {
  let { data } = await axios.get('kuaidi/:id', params)
  return data
}

//编辑订单
async function EditOrder(params) {
  let { data } = await axios.put(`orders/${params.order_id}`, params)
  return data
}

//商品分类请求1（有分页参数）
async function getClass(params) {
  // console.log(params);
  let { data } = await axios.get(`categories?type=${params.type}&pagenum=${params.pagenum}&pagesize=${params.pagesize}`, params)
  return data
}
//商品分类请求2（无分页参数，请求所有数据）
async function getClass2(params) {
  let { data } = await axios.get('categories', params)
  return data
}

//商品分类参数请求
async function parameter(params) {
  // console.log(params);
  let { data } = await axios.get(`categories/${params.id}/attributes?sel=${params.sel}`, params)
  return data
}

//商品图片上传请求
async function upload(params) {
  let { data } = await axios.post('upload', params)
  return data
}

//商品动态参数添加1
async function AddParameter(params) {
  let { data } = await axios.post(`categories/${params.id}/attributes?attr_name${params.attr_name}&attr_sel${params.attr_sel}&attr_vals${params.attr_vals}`, params)
  return data
}

//商品动态参数删除1
async function DelParameter(params) {
  let { data } = await axios.delete(`categories/${params.cat_id}/attributes/${params.attr_id}`, params)
  return data
}

//商品动态参数添加2
async function AddParameter2(params) {
  let { data } = await axios.post(`categories/${params.id}/attributes?attr_name=${params.attr_name}&attr_sel${params.attr_sel}`, params)
  return data
}

//商品参数编辑
async function ModClass(params) {
  let { data } = await axios.put(`categories/${params.cat_id}/attributes/${params.attr_id}?attr_name=${params.attr_name}&attr_sel=${params.attr_sel}&attr_vals=${params.attr_vals}`, params)
  return data
}

//商品参数删除
async function deleteClass(params) {
  let { data } = await axios.delete(`categories/${params.cat_id}/attributes/${params.attr_id}`, params)
  return data
}

//商品分类添加
async function AddClass(params) {
  let { data } = await axios.post('categories', params)
  return data
}

//商品分类编辑
async function EditClass(params) {
  let { data } = await axios.put(`categories/${params.id}`, params)
  return data
}

//商品分类删除
async function delClass(params) {
  let { data } = await axios.delete(`categories/${params}`, params)
  return data
}

//数据报表数据请求
async function getreport(params) {
  let { data } = await axios.get('reports/type/1', params)
  return data
}

export {
  getGo,
  getList,
  getadd,
  getstatus,
  getcom,
  Delete,
  getAll,
  roleList,
  getjur,
  getjur2,
  getAddrole,
  getEdit,
  getDel,
  getAut,
  wipeJur,
  getGoods,
  getCat,
  add,
  edit,
  dels,
  orderList,
  logistics,
  EditOrder,
  getClass,
  getClass2,
  parameter,
  upload,
  AddParameter,
  AddParameter2,
  DelParameter,
  ModClass,
  deleteClass,
  AddClass,
  EditClass,
  delClass,
  getreport,
}